Skip to content

Conversation

@kiyoaki
Copy link
Member

@kiyoaki kiyoaki commented Feb 11, 2026

Summary

  • Change --format from OutputFormat (default hex) to Option<OutputFormat> across all 5 commands
  • When --format is explicitly specified, decode_input uses that format directly without fallback, preventing misdetection (e.g., base64 data that looks like valid hex)
  • When --format is omitted, auto-detection (PEM -> hex -> base64) is preserved for backward compatibility
  • Output encoding defaults to hex when --format is not specified
  • Add 12 unit tests for decode_input covering explicit format, fallback prevention, and auto-detect modes
  • Add 3 integration tests: explicit base64 roundtrip, format mismatch error messages, default hex output

Implements [M-3] from PLANS.md.

Test plan

  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-features -- -D warnings passes
  • cargo clippy --workspace --no-default-features -- -D warnings passes
  • cargo test --workspace --all-features passes (33 tests, 0 failures)
  • CI passes

Change --format from OutputFormat (default hex) to Option<OutputFormat>.
When explicitly specified, decode_input uses that format directly without
fallback, preventing misdetection of base64 data as hex. When omitted,
auto-detection (PEM -> hex -> base64) is preserved for backward
compatibility. Output defaults to hex when --format is not specified.

Add unit tests for decode_input with explicit/auto-detect modes and
integration tests for explicit format roundtrip, format mismatch error
messages, and default hex output verification.
Copilot AI review requested due to automatic review settings February 11, 2026 09:44
@gemini-code-assist
Copy link

Summary of Changes

Hello @kiyoaki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the CLI's robustness and user control over data encoding and decoding. By introducing an explicit --format option for input, it eliminates ambiguity and potential misinterpretations of data that could be valid in multiple formats (e.g., hex vs. base64). This change improves the reliability of cryptographic operations by ensuring data is processed exactly as intended, while still maintaining a convenient auto-detection mechanism for cases where the format is not explicitly provided.

Highlights

  • Input Format Handling: The --format option has been updated across all five CLI commands to accept an Option<OutputFormat>, allowing for explicit format specification or auto-detection.
  • Explicit Format Behavior: When --format is explicitly provided, the input is decoded using the specified format directly, preventing misdetection and fallback to other formats.
  • Auto-detection Preservation: If the --format option is omitted, the existing auto-detection logic (PEM -> hex -> base64) is preserved for backward compatibility.
  • Default Output Format: Output encoding now defaults to hexadecimal when no --format is specified.
  • Testing: Twelve new unit tests were added for the decode_input function, covering explicit format, fallback prevention, and auto-detection modes. Additionally, three new integration tests were introduced for explicit base64 roundtrip, format mismatch error messages, and default hex output.
Changelog
  • PLANS.md
    • Updated the [M-3] entry to reflect the new input format disambiguation approach.
    • Removed an outdated [M-3] entry related to input format improvements.
  • kylix-cli/src/cli.rs
    • Modified the --format argument for all commands to be an Option<OutputFormat> instead of a mandatory OutputFormat.
    • Updated the help text for the --format option to clarify its behavior for input (auto-detect) and output (hex default).
  • kylix-cli/src/commands/decaps.rs
    • Updated the cmd_decaps function signature to accept Option<OutputFormat> for the format parameter.
    • Introduced out_format variable to default to OutputFormat::Hex if format is None for output encoding.
  • kylix-cli/src/commands/encaps.rs
    • Updated the cmd_encaps function signature to accept Option<OutputFormat> for the format parameter.
    • Introduced out_format variable to default to OutputFormat::Hex if format is None for output encoding.
  • kylix-cli/src/commands/keygen.rs
    • Updated the cmd_keygen function signature to accept Option<OutputFormat> for the format parameter.
    • Introduced out_format variable to default to OutputFormat::Hex if format is None for output encoding.
  • kylix-cli/src/commands/sign.rs
    • Updated the cmd_sign function signature to accept Option<OutputFormat> for the format parameter.
    • Introduced out_format variable to default to OutputFormat::Hex if format is None for output encoding.
  • kylix-cli/src/commands/verify.rs
    • Updated the cmd_verify function signature to accept Option<OutputFormat> for the format parameter.
  • kylix-cli/src/io.rs
    • Refactored the decode_input function to handle Option<OutputFormat>, enabling explicit format decoding or auto-detection.
    • Extracted PEM decoding logic into a new private helper function decode_pem.
    • Added detailed error messages for explicit format decoding failures.
    • Implemented comprehensive unit tests for decode_input covering explicit hex, base64, PEM, explicit format preventing fallback, and auto-detection scenarios.
    • Added unit tests for encode_output roundtrips for hex, base64, and PEM.
  • kylix-cli/tests/cli_integration.rs
    • Added an integration test test_explicit_base64_roundtrip to verify correct handling of base64 input/output when explicitly specified.
    • Added an integration test test_format_mismatch_error to ensure helpful error messages are displayed when an explicit format does not match the input.
    • Added an integration test test_default_output_is_hex to confirm that output defaults to hexadecimal when no format is specified.
Activity
  • The author confirmed that cargo fmt --all -- --check passes.
  • The author confirmed that cargo clippy --workspace --all-features -- -D warnings passes.
  • The author confirmed that cargo clippy --workspace --no-default-features -- -D warnings passes.
  • The author confirmed that cargo test --workspace --all-features passes (33 tests, 0 failures).
  • The author indicated that CI passes is pending.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the CLI to treat --format as an explicit input encoding override (when provided), while preserving auto-detection when omitted, to prevent ambiguous hex/base64 misdetection.

Changes:

  • Switched --format from OutputFormat (default hex) to Option<OutputFormat> across commands and decoding logic.
  • Updated decode_input to honor explicit format without fallback, preserving auto-detect only when --format is omitted.
  • Added unit + integration tests covering explicit format behavior, mismatch errors, and default hex output.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
kylix-cli/src/io.rs Implements explicit-vs-auto decode behavior; adds decode helpers and unit tests.
kylix-cli/src/cli.rs Makes --format optional and updates help text across commands.
kylix-cli/src/commands/keygen.rs Defaults output encoding to hex when --format is omitted.
kylix-cli/src/commands/encaps.rs Defaults ciphertext/shared-secret output encoding to hex when --format is omitted.
kylix-cli/src/commands/decaps.rs Defaults shared-secret output encoding to hex when --format is omitted.
kylix-cli/src/commands/sign.rs Defaults signature output encoding to hex when --format is omitted.
kylix-cli/src/commands/verify.rs Updates command signature to accept optional format.
kylix-cli/tests/cli_integration.rs Adds integration tests for explicit format roundtrip, mismatch errors, and default hex output.
PLANS.md Marks the M-3 plan item as implemented with the new behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 28.0 µs 25.0 µs 29.0 µs
liboqs 21.5 µs 18.1 µs 16.5 µs

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 62.0 µs 53.0 µs 45.0 µs
liboqs 19.6 µs 16.5 µs 16.1 µs

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great improvement, introducing an explicit --format option to disambiguate input formats and prevent auto-detection errors. The change from OutputFormat to Option<OutputFormat> is applied consistently across all relevant commands. The addition of comprehensive unit and integration tests significantly improves the robustness of the input decoding logic. I have a couple of suggestions to further improve the new PEM decoding logic and Rust code style.

- Validate -----END footer in decode_pem (Copilot + Gemini)
- Use generic error message listing all formats: hex|base64|pem (Copilot)
- Refactor None branch to if/else if/else expression (Gemini)
- Use &Path instead of to_str().unwrap() in new integration tests (Copilot)
- Use input-only help text for verify's --format arg (Copilot)
@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 28.0 µs 25.0 µs 26.0 µs
liboqs 19.1 µs 19.1 µs 16.4 µs

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 62.0 µs 53.0 µs 44.0 µs
liboqs 19.6 µs 16.4 µs 16.1 µs

- Extract OutputFormat::DEFAULT constant to avoid repeating Hex default
  across 4 command files (keygen, encaps, decaps, sign)
- Add [L-6] PEM Label Validation to PLANS.md for future BEGIN/END
  label mismatch detection in decode_pem
Copilot AI review requested due to automatic review settings February 11, 2026 14:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 38.0 µs 41.0 µs 49.0 µs
liboqs 18.5 µs 20.7 µs 23.6 µs

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 62.0 µs 53.0 µs 44.0 µs
liboqs 19.5 µs 16.4 µs 16.1 µs

- Handle CRLF line endings in decode_pem by normalizing \r (Copilot)
- Replace OutputFormat::DEFAULT with #[derive(Default)] + #[default]
  and use unwrap_or_default() for idiomatic Rust (Copilot)
- Fix test_default_output_is_hex: add empty check and use
  floor_char_boundary for safe string slicing (Copilot)
@kiyoaki kiyoaki requested a review from Copilot February 11, 2026 14:22
@kiyoaki
Copy link
Member Author

kiyoaki commented Feb 11, 2026

/gemini review

@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 28.0 µs 25.0 µs 28.0 µs
liboqs 24.9 µs 26.1 µs 28.0 µs

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 63.0 µs 53.0 µs 44.0 µs
liboqs 19.5 µs 16.5 µs 16.1 µs

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant improvement by disambiguating input formats through an explicit --format option. The changes correctly transition the format argument to Option<OutputFormat> across all relevant commands, allowing users to specify the encoding or rely on robust auto-detection. The decode_input function has been refactored to prioritize explicit format choices and provides helpful error messages when a format mismatch occurs. The addition of a Pem variant to OutputFormat and setting Hex as the default for output when unspecified are well-implemented. The comprehensive suite of unit and integration tests thoroughly validates the new behavior, covering explicit format decoding, fallback prevention, and auto-detection scenarios. Overall, this is a well-executed feature that enhances usability and clarity for input handling.

- Remove line continuation in error messages to avoid embedded
  indentation spaces in output (Copilot)
- Simplify test prefix slice to trimmed.get(..40).unwrap_or(trimmed)
  instead of floor_char_boundary (Copilot)
@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 37.0 µs 27.0 µs 27.0 µs
liboqs 29.7 µs 22.8 µs 19.2 µs

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 62.0 µs 53.0 µs 44.0 µs
liboqs 19.6 µs 16.5 µs 16.2 µs

@kiyoaki kiyoaki requested a review from Copilot February 11, 2026 15:27
@kiyoaki
Copy link
Member Author

kiyoaki commented Feb 11, 2026

/gemini review

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great improvement, successfully disambiguating input formats by making the --format flag optional. When provided, it strictly enforces the format, and when omitted, it maintains backward compatibility with auto-detection. The changes are consistently applied across all relevant commands. The addition of comprehensive unit and integration tests is excellent and covers the new logic well, including edge cases like hex-looking base64 data. I have a couple of minor suggestions for improving code clarity and error handling in io.rs.

…eanup

- Validate PEM BEGIN/END labels match and reject malformed footers
- Use Cow<str> for CRLF normalization in decode_pem
- Extract format_mismatch_msg helper to deduplicate error strings
- Improve auto-detect base64 fallback error to suggest --format
@kiyoaki kiyoaki requested a review from Copilot February 12, 2026 12:34
@kiyoaki
Copy link
Member Author

kiyoaki commented Feb 12, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great improvement for the CLI's usability. Changing --format to an Option and using it to disambiguate input formats is a solid change that prevents misdetection, while preserving backward compatibility through auto-detection. The refactoring of decode_input and the extraction of an improved decode_pem function are well-executed. The addition of comprehensive unit and integration tests demonstrates the quality of this change. I have one minor suggestion for improving error message consistency.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 62.0 µs 53.0 µs 45.0 µs
liboqs 19.4 µs 16.5 µs 16.1 µs

@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 52.0 µs 56.0 µs 26.0 µs
liboqs 26.6 µs 27.5 µs 27.9 µs

- Rename is_hex to is_all_hex_digits for clarity (checks characters,
  not valid encoding)
- Add unit tests: CRLF PEM line endings, empty input auto-detection
- Add integration test: explicit PEM roundtrip (encaps/decaps)
- PLANS.md: move [L-6] PEM label validation to Completed,
  add [L-7] separate --in-format/--out-format flags
- Use strip_prefix/strip_suffix for PEM label extraction instead of
  byte-index slicing to prevent panics on non-ASCII labels
- Add .context(format_mismatch_msg("pem")) to explicit PEM arm for
  consistent error messages across all format branches
- Remove line-continuation backslash in format_mismatch_msg to avoid
  embedded indentation whitespace in error output
- Update keygen --format help text to "Output encoding format" since
  keygen has no input to auto-detect
Copilot AI review requested due to automatic review settings February 12, 2026 12:44
@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 34.0 µs 29.0 µs 28.0 µs
liboqs 31.7 µs 26.9 µs 24.6 µs

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 62.0 µs 54.0 µs 44.0 µs
liboqs 19.5 µs 16.6 µs 16.1 µs

@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 28.0 µs 26.0 µs 32.0 µs
liboqs 24.3 µs 18.4 µs 20.2 µs

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kiyoaki
Copy link
Member Author

kiyoaki commented Feb 12, 2026

/gemini review

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 62.0 µs 53.0 µs 45.0 µs
liboqs 19.6 µs 16.6 µs 16.2 µs

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly improves the CLI's input handling by allowing explicit format specification with the --format option, preventing misdetection and preserving backward compatibility. However, a critical security vulnerability has been identified in the new decode_pem function within io.rs. This function introduces intermediate non-zeroized strings that may leak secret key material in memory, contradicting the project's use of Zeroizing for sensitive data protection. Specifically, the manual CRLF normalization is redundant, and joining PEM body lines should use a protected buffer to prevent sensitive data exposure.

@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 25.0 µs 23.0 µs 24.0 µs
liboqs 16.7 µs 16.3 µs 14.6 µs

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 63.0 µs 54.0 µs 44.0 µs
liboqs 19.4 µs 16.4 µs 16.1 µs

@kiyoaki kiyoaki requested a review from Copilot February 12, 2026 13:04
@kiyoaki
Copy link
Member Author

kiyoaki commented Feb 12, 2026

/gemini review

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an explicit --format option to disambiguate input formats, which is a great improvement for robustness. The implementation is solid, changing the format argument to an Option and handling both explicit and auto-detection cases. The addition of comprehensive unit and integration tests is commendable. My only suggestion is to enhance the error messages in the auto-detection path to be as informative as those for explicit format failures, which will improve the user experience when decoding errors occur.

- Use with_context(|| ...) instead of context(...) to defer String
  allocation to the error path only
- Change format list from pipe-separated to comma-separated for
  user-friendly CLI output
- Add auto-detection context to PEM and hex error messages for
  consistency with base64 fallback message
@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 28.0 µs 25.0 µs 25.0 µs
liboqs 19.2 µs 19.3 µs 18.5 µs

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 63.0 µs 53.0 µs 44.0 µs
liboqs 19.5 µs 16.5 µs 16.1 µs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant